package com.ruoyi.web.controller.system;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.service.MoneyService;
import com.ruoyi.web.controller.utils.SmsUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;

@Api(tags = "资金管理相关")
@RestController
@RequestMapping()
public class MoneyController extends BaseController {

    @Autowired
    MoneyService moneyService;

    @Autowired
    SmsUtil smsUtil;

    @ApiOperation(value = "获取资金管理列表",notes = "system:money:list")
    @PreAuthorize("@ss.hasPermi('system:money:list')")
    @GetMapping("/money/list")
    public AjaxResult moneyList(String userName){
        startPage();
        return AjaxResult.success(getDataTable(moneyService.moneyList(userName)));
    }

    @ApiOperation(value = "根据运营商获取资金明细",notes = "system:operator:money:list")
    @PreAuthorize("@ss.hasPermi('system:operator:money:list')")
    @GetMapping("/operator/money/list")
    public AjaxResult operatorMoneyList(@RequestParam Long operatorId,String orderNum){
        startPage();
        return AjaxResult.success(getDataTable(moneyService.operatorMoneyList(operatorId,orderNum)));
    }

    @ApiOperation(value = "获取资金明细顶头数据",notes = "system:operator:money")
    @PreAuthorize("@ss.hasPermi('system:operator:money')")
    @GetMapping("/operator/money")
    public AjaxResult operatorMoneyIndex(@RequestParam Long operatorId){
        return AjaxResult.success(moneyService.operatorMoneyIndex(operatorId));
    }

    @ApiOperation(value = "运营商申请提现",notes = "system:withdraw:money")
    @PreAuthorize("@ss.hasPermi('system:withdraw:money')")
    @GetMapping("/withdraw/money")
    public AjaxResult withdrawMoney(@RequestParam BigDecimal money, @RequestParam String realName, @RequestParam Integer remitType,String bankName,String number){
        moneyService.withdraw(money,realName,remitType,bankName,number);
        return AjaxResult.success();
    }

    @ApiOperation(value = "运营商申请提现列表",notes = "system:withdraw:list state 0审核中 1以体现 2已拒绝")
    @PreAuthorize("@ss.hasPermi('system:withdraw:list')")
    @GetMapping("/withdraw/list")
    public AjaxResult withdrawList(String phone,String orderNum,Integer state){
        startPage();
        return AjaxResult.success(getDataTable(moneyService.withdrawList(phone,orderNum,state)));
    }

    @ApiOperation(value = "提现审核",notes = "system:withdraw:check")
    @PreAuthorize("@ss.hasPermi('system:withdraw:check')")
    @GetMapping("/withdraw/check")
    public AjaxResult withdrawCheck(@RequestParam Long orderId,Integer type,String reason){
        moneyService.withdrawCheck(orderId,type,reason);
        return AjaxResult.success();
    }

    @ApiOperation("发送手机号验证码")
    @PostMapping("/send/sms")
    public AjaxResult sendSms(@RequestParam String phone){
        smsUtil.sendSms(phone);
        return AjaxResult.success();
    }

    @ApiOperation("运营商绑定手机号")
    @PostMapping("/bind/phone")
    public AjaxResult bindPhone(@RequestParam String phone,@RequestParam String code){
        moneyService.bindPhone(phone,code);
        return AjaxResult.success();
    }
}
